<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>scene.h 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-graphicsview-boxes-example.html">Boxes</a></td><td >scene.h 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">scene.h 示例文件</h1>
<span class="subtitle">graphicsview/boxes/scene.h</span>
<!-- $$$graphicsview/boxes/scene.h-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the demonstration applications of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#ifndef SCENE_H</span>
  <span class="preprocessor">#define SCENE_H</span>

  <span class="comment">//#include &lt;GL/glew.h&gt;</span>
  <span class="preprocessor">#include &quot;glextensions.h&quot;</span>

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>
  <span class="preprocessor">#include &lt;QtOpenGL&gt;</span>

  <span class="preprocessor">#include &quot;roundedbox.h&quot;</span>
  <span class="preprocessor">#include &quot;gltrianglemesh.h&quot;</span>
  <span class="preprocessor">#include &quot;trackball.h&quot;</span>
  <span class="preprocessor">#include &quot;glbuffers.h&quot;</span>
  <span class="preprocessor">#include &quot;qtbox.h&quot;</span>

  <span class="keyword">class</span> QMatrix4x4;

  <span class="keyword">class</span> ParameterEdit : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
  {
  <span class="keyword">public</span>:
      <span class="keyword">virtual</span> <span class="type">void</span> emitChange() <span class="operator">=</span> <span class="number">0</span>;
  };

  <span class="keyword">class</span> ColorEdit : <span class="keyword">public</span> ParameterEdit
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      ColorEdit(<span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span> initialColor<span class="operator">,</span> <span class="type">int</span> id);
      <span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span> color() <span class="keyword">const</span> {<span class="keyword">return</span> m_color;}
      <span class="type">void</span> emitChange() override { <span class="keyword">emit</span> colorChanged(m_color<span class="operator">,</span> m_id); }
  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> editDone();
  <span class="keyword">signals</span>:
      <span class="type">void</span> colorChanged(<span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span> color<span class="operator">,</span> <span class="type">int</span> id);
  <span class="keyword">protected</span>:
      <span class="type">void</span> mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) override;
      <span class="type">void</span> setColor(<span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span> color); <span class="comment">// also emits colorChanged()</span>
  <span class="keyword">private</span>:
      <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> <span class="operator">*</span>m_dialogParentScene;
      <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>m_lineEdit;
      <span class="type"><a href="qframe.html">QFrame</a></span> <span class="operator">*</span>m_button;
      <span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span> m_color;
      <span class="type">int</span> m_id;
  };

  <span class="keyword">class</span> FloatEdit : <span class="keyword">public</span> ParameterEdit
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      FloatEdit(<span class="type">float</span> initialValue<span class="operator">,</span> <span class="type">int</span> id);
      <span class="type">float</span> value() <span class="keyword">const</span> {<span class="keyword">return</span> m_value;}
      <span class="type">void</span> emitChange() override { <span class="keyword">emit</span> valueChanged(m_value<span class="operator">,</span> m_id); }
  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> editDone();
  <span class="keyword">signals</span>:
      <span class="type">void</span> valueChanged(<span class="type">float</span> value<span class="operator">,</span> <span class="type">int</span> id);
  <span class="keyword">private</span>:
      <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> <span class="operator">*</span>m_dialogParentScene;
      <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>m_lineEdit;
      <span class="type">float</span> m_value;
      <span class="type">int</span> m_id;
  };

  <span class="keyword">class</span> GraphicsWidget : <span class="keyword">public</span> <span class="type"><a href="qgraphicsproxywidget.html">QGraphicsProxyWidget</a></span>
  {
  <span class="keyword">public</span>:
      GraphicsWidget() : <span class="type"><a href="qgraphicsproxywidget.html">QGraphicsProxyWidget</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Window) {}
  <span class="keyword">protected</span>:
      <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span> itemChange(GraphicsItemChange change<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qvariant.html">QVariant</a></span> <span class="operator">&amp;</span>value) override;
      <span class="type">void</span> resizeEvent(<span class="type"><a href="qgraphicssceneresizeevent.html">QGraphicsSceneResizeEvent</a></span> <span class="operator">*</span>event) override;
      <span class="type">void</span> paint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qstyleoptiongraphicsitem.html">QStyleOptionGraphicsItem</a></span> <span class="operator">*</span>option<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget) override;
  };

  <span class="keyword">class</span> TwoSidedGraphicsWidget : <span class="keyword">public</span> <span class="type"><a href="../qtcore/qobject.html">QObject</a></span>
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      TwoSidedGraphicsWidget(<span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> <span class="operator">*</span>scene);
      <span class="type">void</span> setWidget(<span class="type">int</span> index<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget);
      <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget(<span class="type">int</span> index);
  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> flip();
  <span class="keyword">protected</span> <span class="keyword">slots</span>:
      <span class="type">void</span> animateFlip();
  <span class="keyword">private</span>:
      GraphicsWidget <span class="operator">*</span>m_proxyWidgets<span class="operator">[</span><span class="number">2</span><span class="operator">]</span>;
      <span class="type">int</span> m_current;
      <span class="type">int</span> m_angle; <span class="comment">// angle in degrees</span>
      <span class="type">int</span> m_delta;
  };

  <span class="keyword">class</span> RenderOptionsDialog : <span class="keyword">public</span> <span class="type"><a href="qdialog.html">QDialog</a></span>
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      RenderOptionsDialog();
      <span class="type">int</span> addTexture(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>name);
      <span class="type">int</span> addShader(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>name);
      <span class="type">void</span> emitParameterChanged();
  <span class="keyword">protected</span> <span class="keyword">slots</span>:
      <span class="type">void</span> setColorParameter(<span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span> color<span class="operator">,</span> <span class="type">int</span> id);
      <span class="type">void</span> setFloatParameter(<span class="type">float</span> value<span class="operator">,</span> <span class="type">int</span> id);
  <span class="keyword">signals</span>:
      <span class="type">void</span> dynamicCubemapToggled(<span class="type">int</span>);
      <span class="type">void</span> colorParameterChanged(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span><span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span>);
      <span class="type">void</span> floatParameterChanged(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span><span class="operator">,</span> <span class="type">float</span>);
      <span class="type">void</span> textureChanged(<span class="type">int</span>);
      <span class="type">void</span> shaderChanged(<span class="type">int</span>);
      <span class="type">void</span> doubleClicked();
  <span class="keyword">protected</span>:
      <span class="type">void</span> mouseDoubleClickEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) override;

      <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span><span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span><span class="operator">&gt;</span> m_parameterNames;
      <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>m_textureCombo;
      <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>m_shaderCombo;
      <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span>ParameterEdit <span class="operator">*</span><span class="operator">&gt;</span> m_parameterEdits;
  };

  <span class="keyword">class</span> ItemDialog : <span class="keyword">public</span> <span class="type"><a href="qdialog.html">QDialog</a></span>
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      <span class="keyword">enum</span> ItemType {
          <span class="type">QtBoxItem</span><span class="operator">,</span>
          CircleItem<span class="operator">,</span>
          SquareItem<span class="operator">,</span>
      };

      ItemDialog();
  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> triggerNewQtBox();
      <span class="type">void</span> triggerNewCircleItem();
      <span class="type">void</span> triggerNewSquareItem();
  <span class="keyword">signals</span>:
      <span class="type">void</span> doubleClicked();
      <span class="type">void</span> newItemTriggered(ItemDialog<span class="operator">::</span>ItemType type);
  <span class="keyword">protected</span>:
      <span class="type">void</span> mouseDoubleClickEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>event) override;
  };

  <span class="keyword">class</span> Scene : <span class="keyword">public</span> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span>
  {
      Q_OBJECT
  <span class="keyword">public</span>:
      Scene(<span class="type">int</span> width<span class="operator">,</span> <span class="type">int</span> height<span class="operator">,</span> <span class="type">int</span> maxTextureSize);
      <span class="operator">~</span>Scene();
      <span class="type">void</span> drawBackground(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> <span class="operator">&amp;</span>rect) override;

  <span class="keyword">public</span> <span class="keyword">slots</span>:
      <span class="type">void</span> setShader(<span class="type">int</span> index);
      <span class="type">void</span> setTexture(<span class="type">int</span> index);
      <span class="type">void</span> toggleDynamicCubemap(<span class="type">int</span> state);
      <span class="type">void</span> setColorParameter(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>name<span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html#QRgb-typedef">QRgb</a></span> color);
      <span class="type">void</span> setFloatParameter(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>name<span class="operator">,</span> <span class="type">float</span> value);
      <span class="type">void</span> newItem(ItemDialog<span class="operator">::</span>ItemType type);
  <span class="keyword">protected</span>:
      <span class="type">void</span> renderBoxes(<span class="keyword">const</span> QMatrix4x4 <span class="operator">&amp;</span>view<span class="operator">,</span> <span class="type">int</span> excludeBox <span class="operator">=</span> <span class="operator">-</span><span class="number">2</span>);
      <span class="type">void</span> setStates();
      <span class="type">void</span> setLights();
      <span class="type">void</span> defaultStates();
      <span class="type">void</span> renderCubemaps();

      <span class="type">void</span> mousePressEvent(<span class="type"><a href="qgraphicsscenemouseevent.html">QGraphicsSceneMouseEvent</a></span> <span class="operator">*</span>event) override;
      <span class="type">void</span> mouseReleaseEvent(<span class="type"><a href="qgraphicsscenemouseevent.html">QGraphicsSceneMouseEvent</a></span> <span class="operator">*</span>event) override;
      <span class="type">void</span> mouseMoveEvent(<span class="type"><a href="qgraphicsscenemouseevent.html">QGraphicsSceneMouseEvent</a></span> <span class="operator">*</span>event) override;
      <span class="type">void</span> wheelEvent(<span class="type"><a href="qgraphicsscenewheelevent.html">QGraphicsSceneWheelEvent</a></span> <span class="operator">*</span> event) override;
  <span class="keyword">private</span>:
      <span class="type">void</span> initGL();
      <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> pixelPosToViewPos(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span><span class="operator">&amp;</span> p);

      <span class="type"><a href="../qtcore/qtime.html">QTime</a></span> m_time;
      <span class="type">int</span> m_lastTime;
      <span class="type">int</span> m_mouseEventTime;
      <span class="type">int</span> m_distExp;
      <span class="type">int</span> m_frame;
      <span class="type">int</span> m_maxTextureSize;

      <span class="type">int</span> m_currentShader;
      <span class="type">int</span> m_currentTexture;
      bool m_dynamicCubemap;
      bool m_updateAllCubemaps;

      RenderOptionsDialog <span class="operator">*</span>m_renderOptions;
      ItemDialog <span class="operator">*</span>m_itemDialog;
      <span class="type"><a href="../qtcore/qtimer.html">QTimer</a></span> <span class="operator">*</span>m_timer;
      GLRoundedBox <span class="operator">*</span>m_box;
      TrackBall m_trackBalls<span class="operator">[</span><span class="number">3</span><span class="operator">]</span>;
      <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span>GLTexture <span class="operator">*</span><span class="operator">&gt;</span> m_textures;
      GLTextureCube <span class="operator">*</span>m_environment;
      GLTexture3D <span class="operator">*</span>m_noise;
      GLRenderTargetCube <span class="operator">*</span>m_mainCubemap;
      <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span>GLRenderTargetCube <span class="operator">*</span><span class="operator">&gt;</span> m_cubemaps;
      <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span><span class="type">QGLShaderProgram</span> <span class="operator">*</span><span class="operator">&gt;</span> m_programs;
      <span class="type">QGLShader</span> <span class="operator">*</span>m_vertexShader;
      <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span><span class="type">QGLShader</span> <span class="operator">*</span><span class="operator">&gt;</span> m_fragmentShaders;
      <span class="type">QGLShader</span> <span class="operator">*</span>m_environmentShader;
      <span class="type">QGLShaderProgram</span> <span class="operator">*</span>m_environmentProgram;
  };

  <span class="preprocessor">#endif</span>

</pre>
</div>
<!-- @@@graphicsview/boxes/scene.h -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
